const JSONKEY = ':json:';
const isNull = value => !value && typeof value !== 'undefined' && value !== 0;


// 通过localstroage存储
export default class Storage {
    set({ key, value }) {
        if(typeof value === 'object') {
            return localStorage.setItem(JSONKEY + key, JSON.stringify(value));
        }
        localStorage.setItem(key, value);
    }
    get(key) {
        let value = localStorage.getItem(key);
        if(isNull(value)) value = JSON.parse(localStorage.getItem(JSONKEY + key));
        
        return value;
    }
}
